Repository navigation
Keep IRSB.extend() from corrupting the appended block and dropping state - #608
Open
NopeCharon wants to merge 2 commits into
Open
NopeCharon wants to merge 2 commits into
NopeCharon wants to merge 2 commits into
Conversation
extend() renumbered the tmps of the appended IRSB's statements in place, so that IRSB was left referring to tmps outside its own type environment. Appending the same IRSB to a second block then failed with an IndexError in IRTypeEnv.lookup(). Extending an empty IRSB also shared the appended block's statement list and type environment, so a later extend() grew the original block as well. The joined block also kept stale derived state from the first block: instruction_addresses, default_exit_target and a cached exit_statements were not updated, and the data_refs and const_vals of the appended block were dropped. lift() joins blocks this way whenever a gym spotter lifts an instruction libVEX cannot decode, so such blocks were missing instruction addresses, the constant default exit target, the data references after the spotter-lifted instruction, and the read-only region constants (for example a folded IAT call target). extend() now renumbers copies of the appended statements, so the appended IRSB is left untouched and can be reused. The joined block concatenates instruction_addresses, takes the appended block's default_exit_target, recomputes exit_statements on demand, and merges data_refs and const_vals with their statement indices offset and their tmps renumbered. lift() discards the block it appends, so it skips the copy through a private _extend() to keep that path as fast as before. Fixes angr#187.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #187.
IRSB.extend()renumbered the tmps of the appended block's statements in place. That left the appended IRSB pointing at tmps outside its own type environment, so appending it to a second block failed withIndexErrorinIRTypeEnv.lookup(). This is the case from the issue. Extending an empty IRSB also shared the appended block's statement list and type environment, so a laterextend()grew the original block too.The joined block also kept stale state from the first block.
instruction_addresses,default_exit_targetand a cachedexit_statementswere never updated, and the appended block'sdata_refsandconst_valswere dropped (the# TODO: Change exit_statements, data_references, etc.).lift()joins blocks this way whenever a gym spotter lifts an instruction that libVEX cannot decode, so this affects normal lifting. Formov rax, [rip+0x100]; swapgs; mov rbx, [rip+0x200]; jz 0x1000on AMD64, master gives:With
load_from_ro_regions/const_prop, an IATcall qword ptr [rip+disp]after a spotter-lifted instruction also loses its folded target inconst_vals.Changes:
extend()now renumbers copies of the appended statements, so the appended IRSB is left unchanged and can be reused. The empty-block path no longer shares the statement list or the type environment.instruction_addresses, takes the appended block'sdefault_exit_target, and recomputesexit_statementson demand. It mergesdata_refsandconst_vals, offsetting their statement indices and renumbering theconst_valstmps.is_noop_blockis true only if both blocks are no-ops.lift()discards the block it appends, so it calls a private_extend(..., copy_statements=False)and skips the copy. That keeps the in-place statement reuse mentioned in the issue thread, and the spotter path is as fast as before (a deep copy there made it about 2.3x slower in a quick benchmark).convert_expr()calls onDirtyargs. Their result was discarded, and the args are already converted throughstmt_.expressions.Test:
tests/test_irsb_extend.pycovers:exit_statementscached before an extendconst_valsafter a spotter-lifted instructionAll five tests fail on master. The full test suite passes with the change.